package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜品分类相关接口")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    @ApiOperation("分页查询分类")
    public Result<PageResult> findCategoryPageQuery(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult categoryPageQuery = categoryService.findCategoryPageQuery(categoryPageQueryDTO);
        return Result.success(categoryPageQuery);
    }
    @PutMapping
    @ApiOperation("修改分类")
    public Result updateCategory(@RequestBody  CategoryDTO categoryDTO){
        log.info("传过来的值是： {}",categoryDTO);
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("传过来的值是： {},{}",status,id);
        categoryService.startOrStop(status,id);
        return Result.success();
    }

    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("传过来的值是：{} ",categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    @GetMapping("/list")
    public Result findCategoryByType(Integer type){
        log.info("传过来的分类查询的值是：{} ",type);
        List<Category> categoryByType = categoryService.findCategoryByType(type);
        return Result.success(categoryByType);
    }
    @DeleteMapping
    public Result deleteCategory(Long id){
        log.info("传过来的值是：{} ",id);
        categoryService.deleteCategory(id);
        return Result.success();
    }
}
